package view;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import controller.KundenController;

public class ListView extends JPanel implements PropertyChangeListener{

	private KundenController controller;
	private DefaultListModel listModel;
	private JList jList;
	
	public ListView(KundenController controller){
		super(new FlowLayout());
		setBorder(BorderFactory.createTitledBorder("Alle Kunden"));
		this.controller = controller;
		controller.getKundenModel().addPropertyChangeListener(this);
		listModel = new DefaultListModel();
		jList = new JList(listModel);
		jList.setPreferredSize(new Dimension(150,150));
		add(new JScrollPane(jList));	
	}

	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		if(evt.getPropertyName().equals("KUNDE_ADD")){
			listModel.addElement(evt.getNewValue());
		}
		
		if(evt.getPropertyName().equals("KUNDE_REMOVE")){
			listModel.removeElement(evt.getNewValue());
		}
		
	}
}